﻿Imports System.Net.Sockets
Imports System.IO

Public Class mainform
#Region "Declare"
    Public Host As String = My.Settings.Host
    Public port As String = My.Settings.port
    Public Sendpage As String = My.Settings.Sendpage

    Public Sender As String
    Public Myip As String = My.Settings.Myip
    Public MyNAme As String = My.Settings.MyNAme
    Public MarkPage As String = My.Settings.MarkPage
    Public AccountType As Integer = 2
    Public TimerDelay As Integer = My.Settings.TimerDelay
    'AT Admin=0 CallCenter = 1 Store = 2
    Public IncludeClose As Boolean = My.Settings.IncludeClose
    Public IncludeRead As Boolean = My.Settings.IncludeRead

    'Connection String
    Public Database As String = My.Settings.Database
    Public Server As String = My.Settings.Server
    Public PersistSecurityInfo As Boolean = My.Settings.PersistSecurityInfo
    Public DBUser As String = My.Settings.DBUser
    Public DBPassword As String = My.Settings.DBPassword
    Public ConnectionString As String = "Data Source=" & Database & ";Data Source=" & Server & ";Persist Security Info=" & PersistSecurityInfo & ";User ID=" & DBUser & ";Password=" & DBPassword

    'CallCenterSettings
    Public GetMaxMyItems As String = My.Settings.GetMaxMyItems
    Public DBTable As String = "[Management_Info_Sys].[dbo].[delivery_items]"
    Public Storestable As String = "[Management_Info_Sys].[dbo].[stores]"
    Public DateFromGetMyItems As Integer = My.Settings.DateFromGetMyItems
    Public OrderBy As String = "[timestamp] asc"
    Public CallCenterGetItemsCommand As String = "SELECT " & GetMaxMyItems & " * from " & DBTable & " where timestamp between '" & Today.AddDays(DateFromGetMyItems) & "' and '" & Today.AddDays(1) & "' and sender ='" & My.Settings.MyNAme.ToUpper & "' order by " & OrderBy & ";"

    'Orders
    Public Mode As Integer = 2
    '1 = SQL
    '2 = Web

    'Include Port
    Public UsePortToSendSignal As Boolean = My.Settings.UsePortToSendSignal
    Public RealPort As Integer = Integer.Parse(My.Settings.RealPort)

    Dim callc As New Form1
    Dim recver As New Receiver
#End Region
    Sub UpgradeMySetings()
        My.Settings.Upgrade()
        My.Settings.Save()
    End Sub
   
    Private Sub mainform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        UpgradeMySetings()
        callc.MainForm = Me
        recver.mainform = Me
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        callc.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        recver.Show()
        Me.Hide()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        If MsgBox("Stop Recieving Deliveries?", vbYesNo, "Kenny Rogers") = vbYes Then
            End
        End If
        End
    End Sub

    Private Sub ShowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShowToolStripMenuItem.Click
        If recver.WindowState = FormWindowState.Minimized Then
            recver.WindowState = FormWindowState.Normal
        End If
        If callc.WindowState = FormWindowState.Minimized Then
            callc.WindowState = FormWindowState.Normal
        End If
        NotifyIcon1.Visible = False
    End Sub

    Dim SettingsView As New Settings
    Private Sub SettingsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SettingsToolStripMenuItem.Click
        If SettingsView.ShowDialog() = Windows.Forms.DialogResult.OK Then
            My.Settings.Reload()
        End If
    End Sub

    Private Sub mainform_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
        For i As Integer = 0 To CommandLineArgs.Count - 1
            If CommandLineArgs(i) = "store" Then
                AccountType = 2
                Me.Hide()
                Me.Visible = False
                recver.Show()
                Exit For
            ElseIf CommandLineArgs(i) = "callcenter" Then
                AccountType = 1
                Me.Hide()
                Me.Visible = False
                callc.Show()
                Exit For
            ElseIf CommandLineArgs(i) = "admin" Then
                AccountType = 0
                Exit For
            End If
        Next
    End Sub

    Private Sub NotifyIcon1_DoubleClick(sender As Object, e As EventArgs) Handles NotifyIcon1.DoubleClick
        If recver.WindowState = FormWindowState.Minimized Then
            recver.WindowState = FormWindowState.Normal
        End If
        If callc.WindowState = FormWindowState.Minimized Then
            callc.WindowState = FormWindowState.Normal
        End If
        NotifyIcon1.Visible = False
    End Sub
End Class